#FROM java:8
FROM openjdk:8
# Default to UTF-8 file.encoding
ENV LANG C.UTF-8

#ENV JAVA_HOME /usr/local/openjdk-8
ENV KAFKA_HOME /usr/local/kafka
ENV SCALA_VERSION 2.12
ENV KAFKA_VERSION 2.2.1
ENV KAFKA_URL_VERSION 2.2.1
ENV KAFKA_TGZ_URL https://mirrors.tuna.tsinghua.edu.cn/apache/kafka/${KAFKA_URL_VERSION}/kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz

ENV PATH $KAFKA_HOME/bin:$PATH

RUN set -eux; \
    wget -O kafka.tgz "${KAFKA_TGZ_URL}" --progress=dot:giga; \
    mkdir -p "$KAFKA_HOME"; \
    tar --extract \
        --file kafka.tgz \
        --directory "$KAFKA_HOME" \
        --strip-components 1 \
        --no-same-owner \
    ; \
    rm kafka.tgz*; \
    { \
        echo '#/bin/sh'; \
        echo 'echo "$KAFKA_HOME"'; \
    } > /usr/local/bin/docker-kafka-home \
    && chmod +x /usr/local/bin/docker-kafka-home \
    && [ "$KAFKA_HOME" = "$(docker-kafka-home)" ] \
    && echo "alias ll='ls -laF'" >> /root/.bashrc

WORKDIR ${KAFKA_HOME}

EXPOSE 9092

# Define default command.
CMD ["bin/kafka-server-start.sh", "config/server.properties --override zookeeper.connect=zookeeper:2181 --override broker.id=0 --override listeners=PLAINTEXT://kafka:9092"]
